package com.mooc.utils;

import java.util.HashMap;
import java.util.Map;

public class MimeTypeUtil {
    private static Map<String,String> map = new HashMap<>();

    static {
        map.put("html", "text/html;charset=utf-8");
        map.put("css", "text/css;charset=utf-8");
        map.put("js", "application/x-javascript;charset=utf-8");
        map.put("jpg", "image/jpeg");
        map.put("png", "image/png");
        map.put("gif", "image/gif");
    }

    public static String getMimeType(String url) {
        //获取文件后缀名
        int index = url.lastIndexOf(".");
        String suffixName = url.substring(index + 1);
        //根据文件后缀名返回对应的mimetpye类型
        return map.get(suffixName);
    }
}
